﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Dataglot;
using NUnit.Framework;

namespace IrishSettings.IntegrationTests.SchemaManagerTests
{

    [TestFixture]
    public class BasicTests
    {
        [SetUp]
        public void Setup()
        {
            TestSettings app = new TestSettings();
            DbApplicationManager appManager = new DbApplicationManager(ConfigUtils.DefaultDataFactory());
            
            appManager.DeleteApplication(app.Application, app.VersionObject);
        }
        [Test]
        public void SaveSchema()
        {
          TestSettings app = new TestSettings();

            DataFactory factory = ConfigUtils.DefaultDataFactory();
          DbApplicationManager appManager = new DbApplicationManager(factory);
          DbSchemaManager schemaManager = new DbSchemaManager(factory);
          SettingsApplication currentApp = appManager.CreateApplication(factory, app, schemaManager);
          DbSchemaManager manager = new DbSchemaManager(currentApp,factory);

          manager.InsertSchema(app.Schema);
          Assert.IsTrue(manager.SchemaIsStored(app, app.VersionObject));
        }

        [Test]
        public void RemoveSchema()
        {
            TestSettings app = new TestSettings();
            DataFactory factory = ConfigUtils.DefaultDataFactory();
            DbApplicationManager appManager =  new DbApplicationManager(factory);
            DbSchemaManager schemaManager = new DbSchemaManager(factory);

            SettingsApplication currentApp = appManager.CreateApplication(factory,app, schemaManager);
            DbSchemaManager manager = new DbSchemaManager(currentApp,factory);
            manager.InsertSchema(app.Schema);
            Assert.IsTrue(manager.SchemaIsStored(app, app.VersionObject));
            appManager.DeleteApplication(app.Application,app.VersionObject);
            Assert.IsFalse(manager.SchemaIsStored(app, app.VersionObject));
        }
    }
}
